﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LabMS.Web.CommonPage
{
    public partial class valuablesselectlist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LabMS.Model.DictionaryClass mDClass = new LabMS.Model.DictionaryClass();
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["location"] == null)
                {
                    Common.JShelper.JSAlert(Page, "err", "参数错误!");
                    return;
                }
                if (Request.QueryString["type"] == null)
                {
                    Common.JShelper.JSAlert(Page, "err", "参数错误!");
                    return;
                }
                string strLocation = Request.QueryString["location"].ToString();
                string strDClass = Request.QueryString["type"].ToString();
                lbType.Text = strDClass;
                lbLocation.Text = strLocation;

                bind(strDClass, strLocation,"");

                lbPageName.Text = mDClass.Name;
            }
            this.Page.Title = lbPageName.Text + this.Page.Title;
        }

        LabMS.Model.DictionaryClass checkQueryString(string strDclass)
        {
            LabMS.BLL.DictionaryClass dicclass = new LabMS.BLL.DictionaryClass();
            string strWhere = " Code = '" + strDclass + "' ";
            List<LabMS.Model.DictionaryClass> listDClass = dicclass.GetModelList(strWhere);
            if (listDClass.Count <= 0)
            {
                return null;
            }
            return listDClass[0];
        }

        public void bind(string strCode, string strLocation, string strCondition)
        {
            LabMS.BLL.InstrumentAndConsumables bconsum = new LabMS.BLL.InstrumentAndConsumables();
            if (strCondition.Trim().Equals(""))
            {
                strCondition = "";
            }
            else
            {
                strCondition = " and " + strCondition;
            }
            string strWhere = " Type = '" + strCode + "'and SpaceLocation= '" + strLocation + "' and Quantity>0 " + strCondition + " order by ID desc ";
            if (strLocation.Equals("@ALL@"))
            {
                strWhere = " Type = '" + strCode + "'and  Quantity>0 " + strCondition + " order by ID desc ";
            }

            List<LabMS.Model.InstrumentAndConsumables> listmconsum = bconsum.GetModelList(strWhere);
            GridView1.DataSource = listmconsum;
            GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");

                e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "','" + e.Row.Cells[2].Text + "','" + e.Row.Cells[3].Text + "','"
                    + "','" + DateTime.Parse(e.Row.Cells[4].Text).ToShortDateString() + "','" + e.Row.Cells[5].Text + "')");
                e.Row.Attributes["style"] = "Cursor:pointer";
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            if (tbKeyWord.Text.Trim().Equals(""))
            {
                bind(lbType.Text, lbLocation.Text, "");
            }
            else
            {
                string strwhere = " like ";
                string strcondition = ddlSType.SelectedValue;
                if (strcondition == "0")
                {
                    strwhere = " Numbers " + strwhere;
                }
                else
                {
                    strwhere = " Name " + strwhere;
                }
                strwhere = strwhere + " '%" + tbKeyWord.Text.Trim() + "%' ";
                bind(lbType.Text, lbLocation.Text, strwhere);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strwhere = " like ";
            string strcondition = ddlSType.SelectedValue;
            if (strcondition == "0")
            {
                strwhere = " Numbers " + strwhere;
            }
            else
            {
                strwhere = " Name " + strwhere;
            }
            strwhere = strwhere + " '%" + tbKeyWord.Text.Trim() + "%' ";
            bind(lbType.Text, lbLocation.Text, strwhere);
        }
    }
}
